package br.com.android.pubclub.negocios;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import br.com.android.pubclub.R;
import br.com.android.pubclub.basicas.Estabelecimento;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapaActivity extends FragmentActivity  {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mapa);
		Estabelecimento est = (Estabelecimento)
				getIntent().getSerializableExtra("estabelecimento");
		 carregaMapa(est);
		
	}
	private void configuraPosicao(GoogleMap map, LatLng latLng) {  
		map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);  
		map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17.0f));  
   }  
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.principal, menu);
		return true;
	}
	
	public void carregaMapa(Estabelecimento estabelecimento){
			//
		String pTitulo = estabelecimento.nome;
		String pSnippet = estabelecimento.telefone; 
		double lat =  Double.valueOf(estabelecimento.latitude);
		double log =  Double.valueOf(estabelecimento.longitude);
		SupportMapFragment fragment =  
			     (SupportMapFragment)getSupportFragmentManager()  
			       .findFragmentById(R.id.map);  
			    GoogleMap map = fragment.getMap();  
			  
			   //LatLng latLng = new LatLng(-8.1083479,-34.9114718);
			   LatLng latLng = new LatLng(lat,log);
			   
			    map.addMarker(new MarkerOptions()  
			      .position(latLng)  
			      .icon(BitmapDescriptorFactory.fromResource(  
			        R.drawable.ic_launcher))  
			      .title(pTitulo)  
			      .snippet(pSnippet));  
			   
			    configuraPosicao(map, latLng);
	}
	public static MapaActivity novaInstancia(Estabelecimento est){
		Bundle args = new Bundle();
		args.putSerializable("estabelecimento", est);		
		MapaActivity cdf = new MapaActivity();
		//cdf.setArguments(args);
		return cdf;
	}

}
